<template>
  <div class="menu-wrapper">
    <!--    <company-dialog ref="officeDialog" @confirm="dialogConfirm" />-->
    <!--    <office-dialog ref="officeDialog" @confirm="officeConfirm"/>-->
    <el-form ref="form" :model="form"  label-width="120px">
      <div
        style="width: 100%;display: flex;align-items: flex-end;border-bottom: 1px #eee solid;margin-bottom: 20px"
      >
        <span style="font-size: 18px;color:#409EFF;margin: 10px 0;">油库信息</span>
      </div>
      <el-form-item label="油库名称:">
        <el-col>
          <span>{{form.warehouse.name}}</span>

        </el-col>
      </el-form-item>
      <!--<el-form-item label="油 库 ID :" prop="id">-->
        <!--<el-col :span="6">-->
          <!--<span>{{form.id}}</span>-->
        <!--</el-col>-->
      <!--</el-form-item>-->
      <el-form-item label="油库编码:">
        <el-col :span="6">
          <span>{{form.warehouse.code}}</span>
        </el-col>
      </el-form-item>
      <el-form-item label="联 系 人 :" >
        <el-col :span="6">
          <span>{{form.warehouse.linkman}}</span>
        </el-col>
      </el-form-item>
      <el-form-item label="联系电话:" >
        <el-col :span="6">
          <span>{{form.warehouse.phone}}</span>
        </el-col>
      </el-form-item>
      <el-form-item label="所属账户:" >
        <el-col>
          <span>{{form.company.name}}</span>
        </el-col>
      </el-form-item>
      <el-form-item label="供 应 商 :">
        <el-col>
          <span>{{form.customer.name}}</span>
        </el-col>
      </el-form-item>
      <el-form-item label="详细地址:" >
        <el-col >
          <span>{{form.warehouse.address}}</span>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" v-permission="['warehouse.edit']" @click="update">修 改</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<style scoped>
.menu-wrapper {
  margin: 15px;
}
</style>
<script>
import permission from "@/directive/permission/index.js"; // 权限判断指令

import {EventBus} from "@/api/eventBus";
import utils from "../../utils/utils.js";
import md5 from "js-md5";
// import Distpicker from "@/components/Distpicker/Distpicker";
import {find} from "@/api/warehouse";

import QueryCompany from "@/components/Query/queryCompany";
import QuerySupplier from "@/components/Query/querySupplier";


export default {
  name: "warehouse-edit",
  components: {
    QuerySupplier,
    QueryCompany,
  },
  directives: {permission},

  data() {
    return {
      disabled:true,
      companyList: [],
      customerList: [],
      pageNum: 1,
      pageSize: 20,
      id: '',
      form: {
        name: "",        //公司名称
        code: "",         //公司Logo
        areaId:'',
        address: "",	    //详情地址
        linkman: "",	    //联系人
        phone: "",        //联系电话
        companyId: '',    //所属公司
        customerId: '',     //供应商
      },
    };
  },
  created() {
    var _this = this;
    _this.getData();
  },
  watch: { // 路由地址不变的情况下,如果id变化则重新获取数据
    $route(newVal, oldVal) {
      if (newVal.name == 'warehouse-edit' && newVal.query.id != this.id) {
        this.getData()
      }
    },

  },
  methods: {

    getData() {
      this.id = this.$route.query.id;
      var _this = this;
      find(_this.id)
        .then(response => {
          console.log("请求返回的数据" + JSON.stringify(response));
          if (response.type == "success") {
            _this.form = response.data;

          } else {
            _this.$message({
              message: response.content,
              offset: 120,
              center: true
            });

          }
        })
        .catch(error => {
        });
    },

    update() {
      this.$router.push({
        path: "/warehouse/edit",
        query: { id: this.id }
      });
    },

    //过滤成日期
    formatDate2Day(val) {
      let date = new Date(val);
      let y = date.getFullYear();
      let MM = date.getMonth() + 1;
      MM = MM < 10 ? "0" + MM : MM;
      let d = date.getDate();
      d = d < 10 ? "0" + d : d;
      return y + "-" + MM + "-" + d;
    },

    //过滤到时间
    formatDate2Time(val) {
      let date = new Date(val);
      let y = date.getFullYear();
      let MM = date.getMonth() + 1;
      MM = MM < 10 ? "0" + MM : MM;
      let d = date.getDate();
      d = d < 10 ? "0" + d : d;
      let h = date.getHours();
      h = h < 10 ? "0" + h : h;
      let m = date.getMinutes();
      m = m < 10 ? "0" + m : m;
      let s = date.getSeconds();
      s = s < 10 ? "0" + s : s;
      return y + "-" + MM + "-" + d + " " + h + ":" + m + ":" + s;
    },

    //过滤企业列表
    formatList(data) {
      data.createDate = this.formatDate2Day(data.createDate);
      data.modifyDate = this.formatDate2Time(data.modifyDate);
      data.rechangeDate = this.formatDate2Time(data.rechangeDate);
      return data;
    },
  }
};
</script>
